package com.innovations.inn.service.impl;

import java.util.List;
import com.innovations.common.utils.DateUtils;
import com.innovations.common.utils.uuid.IdGeneratorSnowflake;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.innovations.inn.mapper.ColumnInformationMapper;
import com.innovations.inn.domain.ColumnInformation;
import com.innovations.inn.service.IColumnInformationService;

/**
 * 栏目信息Service业务层处理
 * 
 * @author dp
 * @date 2024-08-10
 */
@Service
public class ColumnInformationServiceImpl implements IColumnInformationService 
{
    @Autowired
    private ColumnInformationMapper columnInformationMapper;
    @Autowired
    private IdGeneratorSnowflake idGeneratorSnowflake;

    /**
     * 查询栏目信息
     * 
     * @param columnInformationId 栏目信息主键
     * @return 栏目信息
     */
    @Override
    public ColumnInformation selectColumnInformationByColumnInformationId(Long columnInformationId)
    {
        // 点击量加1
        columnInformationMapper.updateColumnInformationClickNum(columnInformationId);
        // 返回查询结果
        return columnInformationMapper.selectColumnInformationByColumnInformationId(columnInformationId);
    }

    /**
     * 查询栏目信息列表
     * 
     * @param columnInformation 栏目信息
     * @return 栏目信息
     */
    @Override
    public List<ColumnInformation> selectColumnInformationList(ColumnInformation columnInformation)
    {
        return columnInformationMapper.selectColumnInformationList(columnInformation);
    }

    /**
     * 新增栏目信息
     * 
     * @param columnInformation 栏目信息
     * @return 结果
     */
    @Override
    public int insertColumnInformation(ColumnInformation columnInformation)
    {
        columnInformation.setCreateTime(DateUtils.getNowDate());
        return columnInformationMapper.insertColumnInformation(columnInformation);
    }

    /**
     * 修改栏目信息
     * 
     * @param columnInformation 栏目信息
     * @return 结果
     */
    @Override
    public int updateColumnInformation(ColumnInformation columnInformation)
    {
        columnInformation.setUpdateTime(DateUtils.getNowDate());
        return columnInformationMapper.updateColumnInformation(columnInformation);
    }

    /**
     * 批量删除栏目信息
     * 
     * @param columnInformationIds 需要删除的栏目信息主键
     * @return 结果
     */
    @Override
    public int deleteColumnInformationByColumnInformationIds(Long[] columnInformationIds)
    {
        return columnInformationMapper.deleteColumnInformationByColumnInformationIds(columnInformationIds);
    }

    /**
     * 删除栏目信息信息
     * 
     * @param columnInformationId 栏目信息主键
     * @return 结果
     */
    @Override
    public int deleteColumnInformationByColumnInformationId(Long columnInformationId)
    {
        return columnInformationMapper.deleteColumnInformationByColumnInformationId(columnInformationId);
    }

    /**
     * 实体数据补全
     *
     * @param columnInformation 实体
     * @param userId       用户id
     * @param crateType    创建类型 1：新增 2：修改
     */
    @Override
    public void completeData(ColumnInformation columnInformation, Long userId, Integer crateType) {
        //主键
        if (columnInformation.getColumnInformationId() == null || "".equals(columnInformation.getColumnInformationId())) {
            columnInformation.setColumnInformationId(idGeneratorSnowflake.nextId());
        }
        //创建人、创建时间
        if (crateType == 1) {
            if (columnInformation.getCreateBy() == null || "".equals(columnInformation.getCreateBy())) {
                columnInformation.setCreateBy(userId);
            }
            if (columnInformation.getCreateTime() == null) {
                columnInformation.setCreateTime(DateUtils.getNowDate());
            }
        }
    }
}
